package com.changgou.pay.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class RabbitMQConfig {

    @Autowired
    private Environment env;
    /**
     * 创建队列
     */
    @Bean
    public Queue orederqueue(){
        return  new Queue(env.getProperty("mq.pay.queue.order"));
    }
    /**
     * 创建交换机
     */
    @Bean
    public Exchange exchange(){
        return  new DirectExchange(env.getProperty("mq.pay.exchange.order"),true,false);
    }
    /**
     * 队列绑定交换机
     */
    @Bean
    public Binding orderBindExchang(Queue orederqueue ,Exchange exchange){
        return  BindingBuilder.bind(orederqueue).to(exchange).with(env.getProperty("mq.pay.routing.key")).noargs();
    }


    /***********************************************秒杀用户***************************************************/

    /**
     * 创建队列
     */
    @Bean
    public Queue orederSeckillqueue(){
        return  new Queue(env.getProperty("mq.pay.queue.seckillorder"));
    }
    /**
     * 创建交换机
     */
    @Bean
    public Exchange exchangeSeckill(){
        return  new DirectExchange(env.getProperty("mq.pay.exchange.seckillorder"),true,false);
    }
    /**
     * 队列绑定交换机
     */
    @Bean
    public Binding orderBindSecillExchang(Queue orederSeckillqueue ,Exchange exchangeSeckill){
        return  BindingBuilder.bind(orederSeckillqueue).to(exchangeSeckill).with(env.getProperty("mq.pay.routing.seckillkey")).noargs();
    }
}
